﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefIssueRecord" :model="stateIssueRecord.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_StationId_FormItem" prop="Entity.StationId" :label="$t('message.autotrans._Model_IssueRecord_Station')">
            <el-select v-model="stateIssueRecord.vmModel.Entity.StationId" clearable>
               <el-option v-for="item in stateIssueRecord.AllStations" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_OpId_FormItem" prop="Entity.OpId" :label="$t('message.autotrans._Model_IssueRecord_OpId')">
            <el-input v-model="stateIssueRecord.vmModel.Entity.OpId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_OpName_FormItem" prop="Entity.OpName" :label="$t('message.autotrans._Model_IssueRecord_OpName')">
            <el-input v-model="stateIssueRecord.vmModel.Entity.OpName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_IssueTypeId_FormItem" prop="Entity.IssueTypeId" :label="$t('message.autotrans._Model_IssueRecord_IssueType')">
            <el-select v-model="stateIssueRecord.vmModel.Entity.IssueTypeId" clearable>
               <el-option v-for="item in stateIssueRecord.AllIssueTypes" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_IssueTypeName_FormItem" prop="Entity.IssueTypeName" :label="$t('message.autotrans._Model_IssueRecord_IssueTypeName')">
            <el-input v-model="stateIssueRecord.vmModel.Entity.IssueTypeName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ReportTime_FormItem" prop="Entity.ReportTime" :label="$t('message.autotrans._Model_IssueRecord_ReportTime')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_IssueRecord_ReportTime')}), trigger: 'blur' }]" >
            <el-date-picker v-model="stateIssueRecord.vmModel.Entity.ReportTime" type='date' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Reporter_FormItem" prop="Entity.Reporter" :label="$t('message.autotrans._Model_IssueRecord_Reporter')">
            <el-input v-model="stateIssueRecord.vmModel.Entity.Reporter" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Description_FormItem" prop="Entity.Description" :label="$t('message.autotrans._Model_IssueRecord_Description')">
            <el-input v-model="stateIssueRecord.vmModel.Entity.Description" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Handler_FormItem" prop="Entity.Handler" :label="$t('message.autotrans._Model_IssueRecord_Handler')">
            <el-input v-model="stateIssueRecord.vmModel.Entity.Handler" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_HandleTime_FormItem" prop="Entity.HandleTime" :label="$t('message.autotrans._Model_IssueRecord_HandleTime')">
            <el-date-picker v-model="stateIssueRecord.vmModel.Entity.HandleTime" type='date' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_HandleResult_FormItem" prop="Entity.HandleResult" :label="$t('message.autotrans._Model_IssueRecord_HandleResult')">
            <el-input v-model="stateIssueRecord.vmModel.Entity.HandleResult" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Status_FormItem" prop="Entity.Status" :label="$t('message.autotrans._Model_IssueRecord_Status')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_IssueRecord_Status')}), trigger: 'blur' }]" >
            <el-select v-model="stateIssueRecord.vmModel.Entity.Status" clearable>
               <el-option key="Pending" value="Pending" :label="$t('message.autotrans._Enum_IssueStatusEnum_Pending')"></el-option>
               <el-option key="Handling" value="Handling" :label="$t('message.autotrans._Enum_IssueStatusEnum_Handling')"></el-option>
               <el-option key="Resolved" value="Resolved" :label="$t('message.autotrans._Enum_IssueStatusEnum_Resolved')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Remark_FormItem" prop="Entity.Remark" :label="$t('message.autotrans._Model_IssueRecord_Remark')">
            <el-input v-model="stateIssueRecord.vmModel.Entity.Remark" clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitIssueRecord"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseIssueRecord"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageAndonManagementIssueRecordEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { issuerecordApi } from '/@/api/andonmanagement/issuerecord';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefIssueRecord = ref();
const stateIssueRecord = reactive({
    vmModel: {
	  Entity:{
        StationId: null,
        OpId: null,
        OpName: '',
        IssueTypeId: null,
        IssueTypeName: '',
        ReportTime: undefined,
        Reporter: '',
        Description: '',
        Handler: '',
        HandleTime: undefined,
        HandleResult: '',
        Status: undefined,
        Remark: '',
        ID:null,
      },

	},
    
    AllStations: [] as any[],
    AllIssueTypes: [] as any[],
});

// 取消
const onCloseIssueRecord = () => {
    closeDialog();
};

// 提交
const onSubmitIssueRecord = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefIssueRecord.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            issuerecordApi().edit(stateIssueRecord.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/AndonManagement/IssueRecord/GetAndonStations',[],false).then(x=>{stateIssueRecord.AllStations = x});
    other.getSelectList('/api/AndonManagement/IssueRecord/GetIssueTypes',[],false).then(x=>{stateIssueRecord.AllIssueTypes = x});
    if (ci.attrs["wtmdata"]) {
		stateIssueRecord.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateIssueRecord.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	issuerecordApi().get(stateIssueRecord.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateIssueRecord.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

